package assetservicelogic

import (
	"context"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/BeanUtils"
	"property_service/utils/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type AssetBasicInfoEditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAssetBasicInfoEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AssetBasicInfoEditLogic {
	return &AssetBasicInfoEditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// AssetBasicInfoEdit 更新资产信息表
func (l *AssetBasicInfoEditLogic) AssetBasicInfoEdit(in *property_service.AssetBasicInfo) (*property_service.Response, error) {
	// 获取资产信息表模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).AssetBasicInfo
	// 构建查询条件：根据ID查询
	do := m.WithContext(l.ctx).Where(m.ID.Eq(in.ID))
	// 执行更新操作，仅更新指定字段，不包含ID、TenantID、StockID、UpdatedAt、CreatedAt
	if _, err := do.UpdateColumns(&model.AssetBasicInfo{
		AssetCode:             in.AssetCode,                               // 资产编码
		AssetName:             in.AssetName,                               // 资产名称
		AssetStatus:           in.AssetStatus,                             // 资产状态
		StatusID:              in.StatusID,                                // 状态ID
		AssetCategory:         in.AssetCategory,                           // 资产分类
		AssetCategoryID:       in.AssetCategoryID,                         // 资产分类ID
		CurrencyID:            in.CurrencyID,                              //币种ID(关联字典表)
		CurrencyName:          in.CurrencyName,                            //币种名称
		AssetValue:            in.AssetValue,                              // 资产原值
		AssetSerialNo:         in.AssetSerialNo,                           // 资产序列号
		CountryOfOrigin:       in.CountryOfOrigin,                         // 产地
		CountryOfOriginID:     in.CountryOfOriginID,                       // 产地ID
		StorageLocation:       in.StorageLocation,                         // 存放地点
		StorageLocationID:     in.StorageLocationID,                       // 存放地点ID
		AssetSource:           in.AssetSource,                             // 资产来源
		AssetSourceID:         in.AssetSourceID,                           // 资产来源ID
		RegistrationNo:        in.RegistrationNo,                          // 注册证书编号
		DocumentNo:            in.DocumentNo,                              // 档案编号
		WarrantyPeriod:        BeanUtils.GetDateFormat(in.WarrantyPeriod), // 保修到期日
		PurchaseDate:          BeanUtils.GetDateFormat(in.PurchaseDate),   // 购买日期
		OriginalAssetCode:     in.OriginalAssetCode,                       // 原资产编码
		AssetStatusFlag:       in.AssetStatusFlag,                         // 资产状态标识
		UsageRoom:             in.UsageRoom,                               // 使用科室
		UsageRoomID:           in.UsageRoomID,                             // 使用科室ID
		AssetOwner:            in.AssetOwner,                              // 资产负责人
		AssetOwnerID:          in.AssetOwnerID,                            // 资产负责人ID
		ImportDate:            BeanUtils.GetDateFormat(in.ImportDate),     // 进口日期
		ManufacturerCode:      in.ManufacturerCode,                        // 生产厂家编码
		ManufacturerCodeID:    in.ManufacturerCodeID,                      // 生产厂家编码ID
		PositionStandard:      in.PositionStandard,                        // 定位标准
		ElectronicTag:         in.ElectronicTag,                           // 电子标签
		AssetType:             in.AssetType,                               // 资产类型
		AssetTypeID:           in.AssetTypeID,                             // 资产类型ID
		AssetModel:            in.AssetModel,                              // 规格型号
		Brand:                 in.Brand,                                   // 品牌
		BrandID:               in.BrandID,                                 // 品牌ID
		WarrantyCertificateNo: in.WarrantyCertificateNo,                   // 保修凭证编号
		PaymentAmount:         in.PaymentAmount,                           // 付款金额
		InvoiceAmount:         in.InvoiceAmount,                           // 发票金额
		InvoiceNo:             in.InvoiceNo,                               // 发票编号
		ContractNo:            in.ContractNo,                              // 合同编号
		SupplierID:            in.SupplierID,                              // 供应商ID
		SupplierName:          in.SupplierName,                            // 供应商
		ManufacturersID:       in.ManufacturersID,                         // 生产商ID
		ManufacturersName:     in.ManufacturersName,                       // 生产商
		MaintenanceID:         in.MaintenanceID,                           // 维保商ID
		MaintenanceName:       in.MaintenanceName,                         // 维保商
		FiscalAssetCode:       in.FiscalAssetCode,                         //财政资产编码(审核的时候填写)
		FiscalAssetName:       in.FiscalAssetName,                         //财政资产名称
		PurchaseOrderID:       in.PurchaseOrderID,                         // 采购订单ID
		PurchaseOrderName:     in.PurchaseOrderName,                       // 采购订单
		StatusName:            in.StatusName,                              // 状态名称
		UpdatedAtuser:         in.UpdatedAtuser,                           // 更新用户
		UseDate:               BeanUtils.GetDateFormat(in.UseDate),        //使用日期
		ManageRoom:            in.ManageRoom,                              //管理科室
		ManageRoomID:          in.ManageRoomID,                            //管理科室ID
		WaysOfChanging:        in.WaysOfChanging,                          //变动方式
		WaysOfChangingID:      in.WaysOfChangingID,                        //变动方式ID
		Unit:                  in.Unit,                                    //单位
		IsManyDepartment:      in.IsManyDepartment,                        //是否多科室
		ManyDepartmentID:      in.ManyDepartmentID,                        //多科室ID
		ManyDepartmentName:    in.ManyDepartmentName,                      //多科室名称
		ManyDepartmentRate:    in.ManyDepartmentRate,                      //多科室占比
		BindingCode:           in.BindingCode,                             //科目分类编码
		BindingName:           in.BindingName,                             //科目分类名称
		SlMj:                  in.SlMj,                                    //数量/面积
		InventoryID:           in.InventoryID,                             //入库单ID
		InventoryCode:         in.InventoryCode,                           //入库单编码
		IsStock:               in.IsStock,                                 //是否在库(0 在库/1 出库)
		PurchaseOrderCode:     in.PurchaseOrderCode,                       //采购订单编码
	}); err != nil {
		// 如果更新失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 更新成功，返回成功响应
	return result.Suc().EditEd()
}
